<?php
require_once("../../config/config.inc.php");

$sAction = fn_getParam("strAction","");
$sEPID   = $SEC->sCorpCD;
//$sEPID = "1";
$aContact = array();

//if ($SEC->sRole == RIGHT_ADMIN) {
    $aContact["allfriend"] = "==== 我的所有朋友 ====";
//}
$sql = "SELECT B.EPID,B.USERNAME,B.TRUENAME,B.PETNAME ";
$sql.= "FROM $TABLE_FRIEND AS A,$TABLE_EP_USER AS B ";
$sql.= "WHERE A.EPID='".$sEPID."' AND A.USERNAME='".$SEC->sUserName."' AND A.LOCKSTATUS='0'";
$sql.= " AND A.EP_ID=B.EPID AND A.USER_NAME=B.USERNAME";
$sql.= " ORDER BY B.USERNAME";
$stmt= $DB->query($sql);
while ($row = $DB->fetchRow($stmt)) {
    $aContact[$row["EPID"]."@".$row["USERNAME"]] = ($row["PETNAME"]=="" ? $row["TRUENAME"] : $row["PETNAME"]);
}
$DB->freeResult($stmt);

//if ($SEC->sRole == RIGHT_ADMIN) {
    $aContact["alluser"] = "==== 我的所有同事或同学 ====";
//}
$sql = "SELECT USERNAME,TRUENAME,PETNAME ";
$sql.= "FROM $TABLE_EP_USER ";
$sql.= "WHERE EPID='".$sEPID."' AND USERNAME!='".$SEC->sUserName."' AND LOCKSTATUS='0'";
$sql.= "ORDER BY USERNAME"; //不能自己发送给自己
$stmt= $DB->query($sql);
while ($row = $DB->fetchRow($stmt)) {
    $aContact[$sEPID."@".$row["USERNAME"]] = ($row["PETNAME"]=="" ? $row["TRUENAME"] : $row["PETNAME"]);
}
$DB->freeResult($stmt);

$SM->assign("aContact",$aContact);

$SM->display('mail/mailContact.html');
?>